<section class="Hui-article-box">
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span>
        角色管理
        <span class="c-gray en">&gt;</span>
        角色编辑
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <article class="cl pd-20">
        <form action="{:U('admin/role/edit')}" method="post" class="form form-horizontal" id="form-admin-role-add">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
                <div class="formControls col-xs-7 col-sm-8">
                    <input type="text" class="input-text" value="{$item['role_name']}" placeholder="" name="role_name"
                        datatype="*4-16" nullmsg="用户账户不能为空">
                </div>
            </div>
            <div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>状态：</label>
				<div class="formControls col-xs-8 col-sm-9 skin-minimal">
					<div class="radio-box">
						<input type="radio" value="1" name="status" {$item['status']==1?'checked':''}>
						<label for="sex-1">开启</label>
					</div>
					<div class="radio-box">
						<input type="radio" value="0" name="status" {$item['status']==0?'checked':''}>
						<label for="sex-2">关闭</label>
					</div>
				</div>
			</div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">权限：</label>
                <div class="formControls col-xs-7 col-sm-8">
                    <foreach name="list" item="item1" key="key1">
                    <dl class="permission-list">
                        <dt>
                            <label>
                                <input type="checkbox" value="{$item1['id']}" name="auth_ids[]" {:in_array($item1['id'],$item['auth'])?'checked':''}>{$item1['auth_name']}
                            </label>
                        </dt>
                        <dd>
                            <foreach name="item1.children" item="item2" key="key2">
                            <dl class="cl permission-list2">
                                <dt>
                                    <label class="">
                                        <input type="checkbox" value="{$item2['id']}" name="auth_ids[]" {:in_array($item2['id'],$item['auth'])?'checked':''}>{$item2['auth_name']}
                                    </label>
                                </dt>
                                <dd>
                                    <foreach name="item2.children" item="item3" key="key3">
                                    <label class="">
                                        <input type="checkbox" value="{$item3['id']}" name="auth_ids[]" {:in_array($item3['id'],$item['auth'])?'checked':''}>{$item3['auth_name']}
                                    </label>
                                    </foreach>
                                </dd>
                            </dl>
                            </foreach>
                        </dd>
                    </dl>
                    </foreach>
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input type="hidden" name="id" value="{$item['id']}">
                    <button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
                </div>
            </div>
        </form>
    </article>
</section>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    $(function () {
        $('.skin-minimal input').iCheck({
			checkboxClass: 'icheckbox-blue',
			radioClass: 'iradio-blue',
			increaseArea: '20%'
		})
        $(".permission-list dt input:checkbox").click(function () {
            $(this).closest("dl").find("dd input:checkbox").prop("checked", $(this).prop("checked"));
        });
        $(".permission-list2 dd input:checkbox").click(function () {
            var l = $(this).parent().parent().find("input:checked").length;
            var l2 = $(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
            if ($(this).prop("checked")) {
                $(this).closest("dl").find("dt input:checkbox").prop("checked", true);
                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", true);
            }
            else {
                if (l == 0) {
                    $(this).closest("dl").find("dt input:checkbox").prop("checked", false);
                }
                if (l2 == 0) {
                    $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", false);
                }
            }
        });

        $("#form-admin-role-add").validate({
            rules: {
                role_name: {
                    required: true,
                },
                status: {
					required: true,
				},
            },
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            submitHandler: function (form) {
                form.submit();
            }
        });
    });
</script>